﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CrudCategories.Web;

namespace CrudCategories
{
    public partial class AddCategory : ChildWindow
    {
        private Category newCategory;

        public Category NewCategory
        {
            get { return newCategory; }
        }
        //private DomainServiceCategory dsCategory = new DomainServiceCategory();

        public AddCategory()
        {
            InitializeComponent();
            this.newCategory = new Category();
            this.DataContext = newCategory;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (!this.newCategory.HasValidationErrors)
            {
                //this.dsCategory.RejectChanges();
                //this.dsCategory.Categories.Add(this.newCategory);
                //this.dsCategory.SubmitChanges(OnAddCompleted, null);
                this.DialogResult = true;
            }
            else
            {
                this.textBoxCategoryName.Focus();
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            textBoxCategoryName.Focus();
            newCategory.CategoryName = string.Empty;
        }

        //private void OnAddCompleted(SubmitOperation submitOp)
        //{
        //    if (!submitOp.HasError)
        //    {
        //        this.DialogResult = true;
        //    }
        //}
    }
}

